﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SpellCaster3
{
    public partial class ErrorForm : Form
    {
        private Exception _Error;

        public ErrorForm()
        {
            InitializeComponent();
            DialogResult = DialogResult.OK;
            stackTraceTextBox.Visible = false;
        }

        public string Message { get { return errorMessageLabel.Text; } set { errorMessageLabel.Text = value; } }

        public Exception Error
        {
            get { return _Error; }
            set
            {
                _Error = value;
                stackTraceTextBox.Visible = (_Error != null);
                if (_Error != null) stackTraceTextBox.Text = _Error.ToString();
            }
        }

        public static DialogResult ShowDefaultErrorBox(string message)
        {
            return MessageBox.Show(message, "Errore", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        public static DialogResult Show(string message, Exception excp = null, IWin32Window window = null)
        {
            ErrorForm frm = new ErrorForm();
            frm.Message = message;
            if (excp != null) frm.Error = excp;

            if (window == null)
            {
                frm.StartPosition = FormStartPosition.CenterScreen;
                return frm.ShowDialog();
            }
            else
                return frm.ShowDialog(window);
        }

        private void okButton_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void ErrorForm_Shown(object sender, EventArgs e)
        {
            System.Media.SystemSounds.Beep.Play();
        }
    }
}
